/*
Copyright 2010,2011 Matt Van Der Westhuizen

This file is part of CGLL.

CGLL is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

CGLL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with CGLL.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.chaoticengine.cgll.input;

import org.chaoticengine.cgll.entity.component.IActiveComponent;

/**
 * The Command class is used to represent any command (input) that
 * can be issued to an Entity with this component.
 */
public abstract class Command {
    public enum Axis {NONE, X, Y};

    protected boolean enabled = false;
    protected IActiveComponent owner = null;

    // Mouse / joystick control elements
    protected int xAxisPixels = 0;
    protected int yAxisPixels = 0;
    protected float xAxisPercentage = 0.0f;
    protected float yAxisPercentage = 0.0f;
    protected int mouseX = 0;
    protected int mouseY = 0;
    protected Axis axis = Axis.NONE;

    public Command(IActiveComponent owner) {
        this.owner = owner;
    }

    public IActiveComponent getOwner() {
        return(this.owner);
    }

    public void enable() {
        enabled = true;
        this.owner.enableCommand(this);
    }

    public void disable() {
        enabled = false;
        this.owner.disableCommand(this);
    }

    public boolean isEnabled() {
        return (enabled);
    }

    public float getXAxisPercentage() {
        return xAxisPercentage;
    }

    public void setXAxisPercentage(float xAxisPercentage) {
        this.xAxisPercentage = xAxisPercentage;
    }

    public int getXAxisPixels() {
        return xAxisPixels;
    }

    public void setXAxisPixels(int xAxisPixels) {
        this.xAxisPixels = xAxisPixels;
    }

    public float getYAxisPercentage() {
        return yAxisPercentage;
    }

    public void setYAxisPercentage(float yAxisPercentage) {
        this.yAxisPercentage = yAxisPercentage;
    }

    public int getYAxisPixels() {
        return yAxisPixels;
    }

    public void setYAxisPixels(int yAxisPixels) {
        this.yAxisPixels = yAxisPixels;
    }

    public int getAxisPixels(Axis ax) {
        if (ax.equals(Axis.X)) {
            return(xAxisPixels);
        } else if (ax.equals(Axis.Y)) {
            return(yAxisPixels);
        } else {
            return(0);
        }
    }

    public void setAxisPixels(Axis ax, int pixels) {
        if (ax.equals(Axis.X)) {
            xAxisPixels = pixels;
        } else if (ax.equals(Axis.Y)) {
            yAxisPixels = pixels;
        }
    }

    public float getAxisPercentage(Axis ax) {
        if (ax.equals(Axis.X)) {
            return(xAxisPercentage);
        } else if (ax.equals(Axis.Y)) {
            return(yAxisPercentage);
        } else {
            return(0.0f);
        }
    }

    public void setAxisPercentage(Axis ax, float percent) {
        if (ax.equals(Axis.X)) {
            xAxisPercentage = percent;
        } else if (ax.equals(Axis.Y)) {
            yAxisPercentage = percent;
        }
    }

    public Axis getAxis() {
        return axis;
    }

    public void setAxis(Axis axis) {
        this.axis = axis;
    }

    public void clearAxisValues() {
        this.xAxisPercentage = 0.0f;
        this.yAxisPercentage = 0.0f;
        this.xAxisPixels = 0;
        this.yAxisPixels = 0;
    }

    public int getMouseX() {
        return mouseX;
    }

    public void setMouseX(int clickX) {
        this.mouseX = clickX;
    }

    public int getMouseY() {
        return mouseY;
    }

    public void setMouseY(int clickY) {
        this.mouseY = clickY;
    }

    public abstract void doAction(int delta);
}
